fix: session isolation, Gemini tool-call correlation, compression failure hardening#45
Merged
Merged
Conversation
…lure hardening Fixes from a full architecture review of the three packages: core: - fromGemini correlates functionResponses via per-name FIFO queues spanning the conversation; repeat calls of the same tool no longer produce duplicate IDs or misattributed results - compression-model failures no longer inject the raw error into the LLM-bound fallback summary (logged via `logger` instead) - onCompress and onBeforeCompress share one degradation stance: a throwing hook is caught and logged, never fails compile() - new SessionPool (LRU, validated maxSize) + normalizeSessionKey / DEFAULT_SESSION_KEY / dedupeConstructionWarnings - new flattenForCompression export — canonical role-flattening for the summarizeHistory compress-callback contract - OpenAIAdapter.compile clones without the JSON round-trip (honors toJSON) - placeholder vocabulary centralized in Prompts ai-sdk-middleware / tanstack-ai: - Janitor state is now per-session (providerOptions.contextChef.sessionId / ctx.conversationId) instead of shared across every conversation the middleware serves; invalid session keys warn once and route to the default slot with unified semantics across both packages - construction-time config nags fire once per middleware, not per session - non-text tool-result parts flatten to typed placeholders instead of being silently dropped - compression flattening reuses core's flattenForCompression - peerDependencies tightened to ^4.0.0 / ^7.0.0 (ai-sdk-middleware)
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the confirmed findings from a full architecture review of all three packages, developed test-first (10+ new tests written red-first).
P0 — correctness
providerOptions: { contextChef: { sessionId } }in the AI SDK middleware,ctx.conversationIdin TanStack). Calls without a session identity share the default slot (prior behavior, zero breaking change). NewmaxSessionscap (default 256, LRU, validated).fromGemini's correlation state was scoped to a single message, sofunctionResponses arriving in a later content entry always fell back to the-0ID — repeat calls of the same tool produced duplicate IDs and misattributed results. Now per-name counters + FIFO queues span the conversation.P1 — failure-path hardening
loggerinstead).onCompressandonBeforeCompressnow share one degradation stance: a throwing hook is caught and logged, never failscompile()(JSDoc contracts updated).SessionPoolrejects non-positivemaxSize(would silently disable pooling).Cleanup
[tool result file: image/png (chart.png)]) instead of being silently dropped; the truncator's duplicate extraction delegates to the same implementation.flattenForCompression(both middlewares reuse it; ~120 lines of copy-paste removed).OpenAIAdapter.compiledrops the per-messageJSON.parse(JSON.stringify(...))round-trip for a direct clone (honorstoJSON, soDatestill lands as ISO string).Prompts;peerDependenciestightened to^4.0.0/^7.0.0.Changesets included for all three packages (core minor, ai-sdk-middleware minor, tanstack-ai minor).
Test plan
pnpm -r run typecheckcleanbiome check .cleanpnpm -r run buildclean